package match.chuanchao;

import com.alibaba.fastjson2.JSONObject;
import match.chuanchao.dto.OrderGuanSaiRenInfo;
import okhttp3.*;

/**
 * @author xiang.liao
 * @create 2025/11/3
 */
public class Chuanchao {

  // 这个其实可以不要
  public static String addToCardPage = "https://client.maitix.com/api/trade/addCartGood";
  public static String guansairen = "https://client.maitix.com/api/trade/confirmGroupedCart";
  // 下单页面，这里要返回订单号
  public static String addOrder = "https://client.maitix.com/api/trade/submitGroupedCart";
  public static String eventId = "252324018";

  private static String header = ":authority\n" +
          "client.maitix.com\n" +
          ":method\n" +
          "GET\n" +
          ":path\n" +
          "/api/user/userInfo?langType=1\n" +
          ":scheme\n" +
          "https\n" +
          "_r\n" +
          "21\n" +
          "Accept\n" +
          "*/*\n" +
          "Accept-Encoding\n" +
          "gzip, deflate, br, zstd\n" +
          "Accept-Language\n" +
          "zh-CN,zh;q=0.9\n" +
          "Coeus\n" +
          "10086\n" +
          "Cookie\n" +
          "cna=mrWAIeq+nAcCAbfeylSzsS/q; MZOPERATEID=NDkxNjA1NTA; MZCONSUMERJSESSIONID=fc3bf864c543463b84670b15ad23a580; xlly_s=1; JSESSIONID=C4C1CF00D755BC1FFF46F00D44C52922; isg=BLe3WC7HkoYClxf7PgnYNBWWRqsBfIvev30-sAlk0gbtuNX6EU1sLmranh7mUGNW; tfstk=g05rALaY27Fr5MobNidE7Md2b8RJsBr6t6tB-wbHP3xkVuneYgIpKLwRFeVFyn1WVaOk0i71JTTQqzBe-G_Bqa_QvXuHws6SO3ZJTwj6TlZ_15_Rypd3fl_MQiGw_enoEDtkiQLQPKfVw5_Ryq0rxP601WuRIdKHxMvkoxYMmbchxbx0ueYIqvclxZ42DeonKeYkinYeSXAHtMb0ueKDrBvlxZ42JnxnI351_x8WErT3AO4qV5dJjaxqtfuezLxa6nhntsRRuhboBXchgUJliWo5nTJ5KNpONsVEMQ_NnIY1y7l2saYNVnsgsjRclZjBBtEK1QsVTd5Xe2qpEgWc59v4r7b2a3J1aigi3QWh26JRU2UOoQjABhpuHoLVN19eXKo0qZ_2qdWFVohHVO7c0d1jcfOdD9jH8imP4GopoIUc9TonLLYvuha4uEPX4x-9m6nrpvpktE-_onDKpLYvuha4uvHpEBY2frxc.\n" +
          "Epeius\n" +
          "1762154258604\n" +
          "Hecate\n" +
          "3102d69e9e10bb6b3652631c10e1b24c\n" +
          "Mzoperateid\n" +
          "NDkxNjA1NTA\n" +
          "Origin\n" +
          "https://scgchc.maitix.com\n" +
          "Priority\n" +
          "u=1, i\n" +
          "Referer\n" +
          "https://scgchc.maitix.com/\n" +
          "Sec-Ch-Ua\n" +
          "\"Google Chrome\";v=\"141\", \"Not?A_Brand\";v=\"8\", \"Chromium\";v=\"141\"\n" +
          "Sec-Ch-Ua-Mobile\n" +
          "?1\n" +
          "Sec-Ch-Ua-Platform\n" +
          "\"Android\"\n" +
          "Sec-Fetch-Dest\n" +
          "empty\n" +
          "Sec-Fetch-Mode\n" +
          "cors\n" +
          "Sec-Fetch-Site\n" +
          "same-site\n" +
          "Site\n" +
          "m\n" +
          "User-Agent\n" +
          "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Mobile Safari/537.36\n" +
          "X-Mz-Session\n" +
          "fc3bf864c543463b84670b15ad23a580\n" +
          "X-Xsrf-Token\n" +
          "bfaad446531e43b198620ccb30271632";

  public static void main(String[] args) {
    String[] split = header.split("\n");
    System.out.println(split.length);
    OkHttpClient client = new OkHttpClient();
    // 创建一个Request对象，并添加自定义的Header
    Request.Builder builder = new Request.Builder();
    builder.url(guansairen);
    for (int i = 0; i < split.length; i++,i++) {
      builder.addHeader(split[i], split[i+1]);
    }
    OrderGuanSaiRenInfo orderGuanSaiRenInfo = new OrderGuanSaiRenInfo();
    OrderGuanSaiRenInfo.CheckGoods checkGoods = new OrderGuanSaiRenInfo.CheckGoods();
    checkGoods.setEventId(eventId);
    orderGuanSaiRenInfo.getCheckGoods().add(checkGoods);

    MediaType JSON = MediaType.parse("application/json;charset=utf-8");
    RequestBody body = RequestBody.create(JSON, JSONObject.toJSONString(orderGuanSaiRenInfo));
    builder.post(body);
    Request request = builder.build();
    try {
      // 发送请求并获取响应
      Response response = client.newCall(request).execute();
      System.out.println(response.body().string()); // 打印响应体
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
